import { ElMessage } from "element-plus";
import request from "../utils/request";
interface Option {
	label : string;
	color : string;
	value : string | number;
}
interface Tag {
	text : string;
	bg : string;
	value : string | number;
}
/**
 * 项目通用数据字典api
 */
export const getShipments = async (type : string, type1 : string = 'option') : Promise<Option[] | Tag[]> => {
	const newOptions = [];
	const result = await request({
		url: 'SalesReceipt/selectDict', //login/selectShipment //demand/selectDictDataByType
		params: {
			type
		}
	});
	// console.log('selectShipment --->', result);
	if (result.data.code !== 200) {
		//
		ElMessage.error({
			showClose: true,
			message: result.data.msg
		});
		return newOptions;
	}
	// option start
	if (type1 === 'option') {
		result.data.t.forEach((item : any) => {
			newOptions.push({
				label: item?.status || item?.dictLabel,
				color: item?.classColor ? JSON.parse(item?.classColor).color : JSON.parse(item?.cssClass).color,
				value: item?.id || item?.dictCode
			});
		});
	}
	// option end

	// tag start
	if (type1 === 'tag') {
		result.data.t.forEach((item : any) => {
			newOptions.push({
				text: item?.status || item?.dictLabel,
				bg: item?.classColor ? JSON.parse(item?.classColor).color : JSON.parse(item?.cssClass).color,
				value: item?.id || item?.dictCode
			});
		});
	}
	// tag end
	return newOptions;
}